﻿using BackData;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rabbit.API.Application.Command.Goods;
using Rabbit.API.DTOs;

namespace Rabbit.API.Controllers
{
    /// <summary>
    /// 商品控制器  
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class GoodsController : ControllerBase
    {
        IMediator mediator;

        public GoodsController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 商品添加  批次+许可证号在前端后端都可生成 图片单添加
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpPost]
        public Task<APIResult<int>> GoodsAdd(GoodsAddCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取商品信息列表  已完成简单分页
        /// </summary>
        /// <param name="request">分页</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>获取商品信息列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<APIPaging<GoodsDTO>> GoodsGet([FromQuery] GoodsGetCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 商品信息删除  单删
        /// </summary>
        /// <param name="request">主键</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpDelete]
        public Task<APIResult<int>> GoodsDel([FromQuery] GoodsDelCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 商品信息修改
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<APIResult<int>> GoodsUpdate(GoodsUpdateCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 商品信息详情
        /// </summary>
        /// <param name="request">主键</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>商品信息</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<APIResult<GoodsDTO>> GoodsModel([FromQuery] GoodsModelCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
